import {get_w_h, setConfirm} from "./domFn";

const doc = document;
const layer = doc.getElementById('layer');
const modal = doc.getElementsByClassName('modal')[0]
const footer = doc.getElementsByTagName('footer')[0]
const modalDom = layer.getElementsByClassName('modal-box')[0]
const modalArrowHeight = 35;


export const isShowTop = (_this) => {
  const {bottom, offsetHeight} = get_w_h(_this);
  const {height} = get_w_h(modal)
  const {height: footerHeight} = get_w_h(footer)
  return offsetHeight() - bottom - footerHeight - modalArrowHeight < height;
}

export const getModalAllHeight = () => {
  const {height} = get_w_h(modal)
  const {height: footerHeight} = get_w_h(footer)
  return height + footerHeight + modalArrowHeight * 2;
}
export const clickInitModal = (_this) => {
  const {top, left} = get_w_h(_this);
  layer.classList.remove('hide');
  isShowTop(_this) ? setConfirm(modalDom, top - getModalAllHeight(), left) : setConfirm(modalDom, top, left);
}
export const isReverseModalArrow = (_this, top, left, isScroll) => {
  if (isShowTop(_this)) {
    layer.classList.add('reverse')
    isScroll && setConfirm(modalDom, top - getModalAllHeight(), left)
  } else {
    layer.classList.remove('reverse')
    isScroll && setConfirm(modalDom, top, left)
  }
}
